package com.xizimall.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xizimall.mapper.TbItemCatMapper;
import com.xizimall.pojo.TbItemCat;
import com.xizimall.pojo.TbItemCatExample;
import com.xizimall.pojo.TbItemCatExample.Criteria;
import com.xizimall.service.ItemCatService;
import com.xizimall.common.pojo.EUTreeNode;
/**
 * 商品分类列表,分列管理
 * <p>Title: ItemCatServiceImpl</p>
 * <p>Description: </p>
 * <p>华南理工大学研究生</p> 
 * @author	李隆熹
 * @date	2018年4月12日下午4:43:25
 * @version 1.0
 */
@Service
public class ItemCatServiceImpl implements ItemCatService {
    @Autowired
    private TbItemCatMapper itemCatMapper;
	@Override
	public List<EUTreeNode> getItemCatList(Long parentId) {
		//创建查询条件
		TbItemCatExample example =new TbItemCatExample();
		Criteria criteria=example.createCriteria();
		criteria.andParentIdEqualTo(parentId);
		List<TbItemCat> list=itemCatMapper.selectByExample(example);
		//把列表转换成TreeNodelist
		List<EUTreeNode> resultList=new ArrayList<>();
		for ( TbItemCat itemCat:list ) {
			EUTreeNode euTreeNode=new EUTreeNode();
			euTreeNode.setId(itemCat.getId());
			euTreeNode.setText(itemCat.getName());
			euTreeNode.setState(itemCat.getIsParent()?"closed":"open");
			resultList.add(euTreeNode);
		}
		
		return resultList;
	}

}
